package com.iteaj.util.http;

import com.iteaj.util.core.UtilsException;
import com.iteaj.util.http.adapter.HttpClientAdapter;
import com.iteaj.util.http.adapter.JdkHttpAdapter;
import com.iteaj.util.http.build.MultipartBuilder;
import com.iteaj.util.http.build.StreamBuilder;
import com.iteaj.util.http.build.UrlBuilder;

/**
 * create time: 2018/3/27
 *  Http适配器, 用于适配HttpClient{@link HttpClientAdapter} 、<br>
 *      jdk自带{@link java.net.HttpURLConnection} {@link JdkHttpAdapter}等.
 *      向外提供一套简单易用的统一的Api
 * @author iteaj
 * @version 1.0
 * @since 1.7
 */
public interface HttpAdapter<T extends HttpResponse> {

    /**
     *  使用{@link ContentType#UrlEncoded}发送Get请求
     * @param builder  http请求需要的配置信息以及参数信息
     *
     * @return
     * @throws UtilsException
     */
    T get(UrlBuilder builder) throws UtilsException;

    /**
     *使用{@link ContentType#UrlEncoded}发送POST请求
     * @param builder http请求需要的配置信息以及参数信息
     * @return
     * @throws UtilsException
     */
    T post(UrlBuilder builder) throws UtilsException;

    /**
     * 流实体构建器, 参数放入body里面, 没有参数名. {@link ContentType}主要有以下几种<br>
     *     1. {@link StreamBuilder#setForJson(String)} {@link ContentType#Json}
     *     2. {@link StreamBuilder#setForHtml(String)} {@link ContentType#Html}
     *     3. {@link StreamBuilder#setForXml(String)} {@link ContentType#Xml}
     *     4. {@link StreamBuilder#setForPlain(String)} {@link ContentType#Plain}
     *     5. {@link StreamBuilder#setForStream(byte[])} {@link ContentType#OctetStream}
     *
     * @param builder http请求需要的配置信息以及参数信息
     *
     * @see StreamBuilder#setForPlain(String)
     * @return
     * @throws UtilsException
     */
    T post(StreamBuilder builder) throws UtilsException;

    /**
     * 发送Post请求, {@link ContentType#Multipart}
     * @param builder http请求需要的配置信息以及参数信息
     *
     * @return
     * @throws UtilsException
     */
    T post(MultipartBuilder builder) throws UtilsException;

}
